/*
  ! 如果没有天赋，那就一直重复
  ! Created: 2024/06/15 07:46:39
*/
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
// #define int long long
#define mp(x, y) make_pair(x, y)
#define eb(...) emplace_back(__VA_ARGS__)
#define fro(i, x, y) for (int i = (x); i <= (y); i++)
#define pre(i, x, y) for (int i = (x); i >= (y); i--)
inline void JYFILE19();

using i64 = long long;
using PII = pair<int, int>;

bool ST;
const int N = 1e6 + 10;
const int mod = 998244353;

int n, m, ct, fa[N], ds[N], sa[N], rk[N], ma[N << 1], head[N];
struct edge {
  int to, nxt, val;
} e[N << 2];

inline int gf(int x) {
  return (fa[x] == x ? fa[x] : fa[x] = gf(fa[x]));
}
inline void mer(int x, int y) {
  x = gf(x), y = gf(y);
  if (x > y) swap(x, y);
  fa[x] = y;
}
inline void add(int x, int y, int z) {
  e[++ct] = {y, head[x], z}, head[x] = ct;
}
inline void solve() {
  cin >> n;
  fro(i, 1, n) cin >> sa[i];
  fro(i, 1, n) sa[i]++;
  fro(i, 1, n) rk[sa[i]] = i;
  fro(i, 1, n * 2 - 1) cin >> ma[i];
  iota(fa + 1, fa + n + 1, 1);
  for (int i = 1, R = 0; i <= n * 2 - 1; i++) {
    if (ma[i] == 0) continue;
    int l = ((i - 1) / 2) - (ma[i] + 1) / 2 + 2;
    int r = ((i - 0) / 2) + (ma[i] + 1) / 2 + 0;
    if (!(1 <= l && l <= r && r <= n))
      return cout << -1 << "\n", void();
    fro(j, max(i / 2 + 1, R + 1), r) {
      mer(rk[l + (r - j)], rk[j]);
    }
    R = max(R, r);
  }
  for (int i = 1, r = 1; i <= n; i++) {
    if (r < i) r = i;
    if (r < gf(i)) mer(r, gf(i));
    r = max(r, gf(i)), mer(i, r);
  }
  fro(i, 1, n - 1)
    add(gf(i + 1), gf(i), rk[sa[i + 1] + 1] <= rk[sa[i] + 1]);
  for (int i = 1; i <= n * 2 - 1; i++) {
    int l = ((i - 1) / 2) - (ma[i] + 1) / 2 + 2;
    int r = ((i - 0) / 2) + (ma[i] + 1) / 2 + 0;
    l--, r++;
    if (1 <= l && l <= r && r <= n) {
      if (gf(rk[l]) == gf(rk[r])) return cout << -1 << "\n", void();
      if (rk[l] > rk[r]) add(gf(rk[l]), gf(rk[r]), 1);
      if (rk[l] < rk[r]) add(gf(rk[r]), gf(rk[l]), 1);
    }
  }
  fro(i, 1, n)
    for(int j = head[i]; j; j = e[j].nxt)
      ds[i] = max(ds[e[j].to] + e[j].val, ds[i]);
  fro(i, 1, n) if (ds[i] >= 26) return cout << -1 << "\n", void();
  fro(i, 1, n) cout << (char)('a' + ds[gf(rk[i])]); cout << "\n";
}

signed main() {
  JYFILE19();
  int t;
  cin >> t;
  while (t--) {
    solve();
    ct = 0;
    fro(i, 1, n) sa[i] = rk[i] = ds[i] = head[i] = 0;
    fro(i, 1, n * 2 - 1) ma[i] = 0;
  }
  return 0;
}

bool ED;
inline void JYFILE19() {
  freopen("string.in", "r", stdin);
  freopen("string.out", "w", stdout);
  srand(random_device{}());
  ios::sync_with_stdio(0), cin.tie(0);
  double MIB = fabs((&ED - &ST) / 1048576.), LIM = 1024;
  cerr << "MEMORY: " << MIB << endl, assert(MIB <= LIM);
}